/**
 * 作者: clz
 * 日期: 2025-03-24 17:32:58
 * 备注: 聊天记录表（单服+全服）
 */
package com.motu.monstercity.server.game.userdata;

import com.motu.vertx.module.utility.model.BaseModel;
import com.motu.vertx.module.utility.model.Model;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;

public class ChatPublicModel extends BaseModel implements Model {
	public static final String LISTKEY = "group_id";
	public static final int REDIS_EXPIRE_TIME = 0;// redis过期时间
	public static final int UPDATE_DB_TYPE = UPDATE_DB_TYPE_QUEUE;// 数据入库类型 队列入库
	public static final boolean ORDER_LIST = true;// 是否需要额外的有序列表

	protected long id; // ID
	protected int chatType; // 聊天类型 (0-世界公聊)
	protected int subType; // 子类型 (0-普通)
	protected int groupId; // 聊天分类ID (数据分组ID 作为listkey)
	protected int serverId; // 用户所在服务器Id
	protected long userId; // 用户ID
	protected String userName = ""; // 用户名字
	protected String content = ""; // 聊天内容
	protected String param = ""; // 附加参数
	protected long addTime; // 插入时间

	public void reset() {
	}

	protected String getKey() {
		return "ChatPublic." + id;
	}

	protected String getListKey() {
		return "ChatPublic." + groupId;
	}

	protected String getListItemKey() {
		return id + "";
	}

	public void doCreate() {
		setTableId();
		insert();
	}

	public void setTableId() {
		putId(incrTableId("chat_public"));
	}

	public JsonObject insert() {
		return super.insert(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
	}

	public void delete() {
		super.delete(getKey(), id, UPDATE_DB_TYPE, 0, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
	}

	/**
	 * 根据入库类型更新
	 */
	public JsonObject update() {
		return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
	}

	/**
	 * 实时入队列
	 */
	public JsonObject updateQueueNow() {
		return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
	}

	public JsonObject getAllObj(){
		JsonObject obj = new JsonObject();
		obj.put("id", id); // ID
		obj.put("chatType", chatType); // 聊天类型 (0-世界公聊)
		obj.put("subType", subType); // 子类型 (0-普通)
		obj.put("groupId", groupId); // 聊天分类ID (数据分组ID 作为listkey)
		obj.put("serverId", serverId); // 用户所在服务器Id
		obj.put("userId", userId); // 用户ID
		obj.put("userName", userName); // 用户名字
		obj.put("content", content); // 聊天内容
		obj.put("param", param); // 附加参数
		obj.put("addTime", addTime); // 插入时间
		return obj;
	}

	public long getId() {
		return id;
	}

	public void putId(long id) {
		if (this.id != id) {
			this.id = id;
			updateRedisHashField(getKey(), "id", this.id);
		}
	}

	public void addId(long value) {
		this.id += value;
		updateRedisHashField(getKey(), "id", this.id);
	}

	public int getChatType() {
		return chatType;
	}

	public void putChatType(int chatType) {
		if (this.chatType != chatType) {
			this.chatType = chatType;
			updateRedisHashField(getKey(), "chatType", this.chatType);
		}
	}

	public void addChatType(int value) {
		this.chatType += value;
		updateRedisHashField(getKey(), "chatType", this.chatType);
	}

	public int getSubType() {
		return subType;
	}

	public void putSubType(int subType) {
		if (this.subType != subType) {
			this.subType = subType;
			updateRedisHashField(getKey(), "subType", this.subType);
		}
	}

	public void addSubType(int value) {
		this.subType += value;
		updateRedisHashField(getKey(), "subType", this.subType);
	}

	public int getGroupId() {
		return groupId;
	}

	public void putGroupId(int groupId) {
		if (this.groupId != groupId) {
			this.groupId = groupId;
			updateRedisHashField(getKey(), "groupId", this.groupId);
		}
	}

	public void addGroupId(int value) {
		this.groupId += value;
		updateRedisHashField(getKey(), "groupId", this.groupId);
	}

	public int getServerId() {
		return serverId;
	}

	public void putServerId(int serverId) {
		if (this.serverId != serverId) {
			this.serverId = serverId;
			updateRedisHashField(getKey(), "serverId", this.serverId);
		}
	}

	public void addServerId(int value) {
		this.serverId += value;
		updateRedisHashField(getKey(), "serverId", this.serverId);
	}

	public long getUserId() {
		return userId;
	}

	public void putUserId(long userId) {
		if (this.userId != userId) {
			this.userId = userId;
			updateRedisHashField(getKey(), "userId", this.userId);
		}
	}

	public void addUserId(long value) {
		this.userId += value;
		updateRedisHashField(getKey(), "userId", this.userId);
	}

	public String getUserName() {
		return userName;
	}

	public void putUserName(String userName) {
		if (!this.userName.equals(userName)) {
			this.userName = userName;
			updateRedisHashField(getKey(), "userName", this.userName);
		}
	}

	public String getContent() {
		return content;
	}

	public void putContent(String content) {
		if (!this.content.equals(content)) {
			this.content = content;
			updateRedisHashField(getKey(), "content", this.content);
		}
	}

	public String getParam() {
		return param;
	}

	public void putParam(String param) {
		if (!this.param.equals(param)) {
			this.param = param;
			updateRedisHashField(getKey(), "param", this.param);
		}
	}

	public long getAddTime() {
		return addTime;
	}

	public void putAddTime(long addTime) {
		if (this.addTime != addTime) {
			this.addTime = addTime;
			updateRedisHashField(getKey(), "addTime", this.addTime);
		}
	}

	public void addAddTime(long value) {
		this.addTime += value;
		updateRedisHashField(getKey(), "addTime", this.addTime);
	}

}